<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/4/21
 * Time: 9:28
 */
define('app_path',dirname(dirname(__FILE__)).'/');
require_once '../vendor/autoload.php';

// 引入鉴权类
use admin\helper\qiniu;
use admin\helper\upload;


$callback = isset($_GET['callback']) ? $_GET['callback'] : '';
$action   = isset($_GET['action']) ? $_GET['action'] : '';
if ($action == 'config') { //百度编辑器
    $result = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("./template/plugins/ue/php/config.json")), true);
}
else {
	
    $type   = isset($_GET['type']) ? $_GET['type'] : '';
    $txt = isset($_POST['txt'])? $_POST['txt']:'';
    $upFileType = $_FILES['upfile']['type'];
	 $result = qiniu::upload($type);	
	 /*
    if($txt && strpos($upFileType, 'video') == false && strpos($upFileType, 'gif') == false)
    {
		//echo $txt;exit;
        //如果上传水印则加水印 jimmy
        //先上传
        $upload = new admin\helper\upload();
        $file = $upload->uploadImg();
        if(!$file['state'])
        {
            echo json_encode(['state'=>'FAIL']);
            exit;
        }
        //加水印
        $files = $upload->imgTxt($file['fileName'],$txt);
        if(!$files)
        {
            echo json_encode(['state'=>'FAIL']);
            exit;
        }

        //上传到7牛
        $result = qiniu::uploadImgTxt($type,$files);
    }
    else{		
        $result = qiniu::upload($type);		
	
    }
	*/

}



$result = json_encode($result);
/* 输出结果 */
if (isset($_GET["callback"])) {
    if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
        echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
    }
    else {
        echo json_encode(array(
            'state' => 'callback参数不合法'
        ));
    }
}
else {
    echo $result;
}
?>
